package lormi.meipin.controller.api;

import lormi.meipin.common.Result;
import lormi.meipin.controller.BaseController;
import lormi.meipin.dto.CurrencyDto;
import lormi.meipin.exception.LMException;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 职位关注
 * */
@RestController
@RequestMapping(value="v2/focusposition/",method=RequestMethod.POST,produces = "application/json; charset=utf-8")
public class FocusPositionController extends BaseController{

	/**
	 * 个人=》关注(收藏)一个职位
	 * @Param userid 用户ID
	 * @Param usertype 用户类型
	 * @Param positionid 关注的职位ID
	 * */
	@RequestMapping("focus")
	@Valid
	public String focusPosition(@NotNull(message="100033") @RequestParam(value="userid",required=false) Integer userid,
			@NotNull(message="100033") @RequestParam(value="positionid",required=false) Integer positionid) throws Exception{
		
		focusPositionService.focusPosition(userid, positionid);
		return Result.success();
	}
	
	/**
	 * 个人=》取消对一个职位的关注
	 * @Param userid 用户ID
	 * @Param usertype 用户类型
	 * @Param id 关注职位ID
	 * */
	@RequestMapping("cancel")
	@Valid
	public String delFocusPosition(@NotNull(message="100033") @RequestParam(value="userid",required=false) Integer userid,
			@NotNull(message="100033") @RequestParam(value="id",required=false) Integer id) throws LMException{
		
		focusPositionService.cancelFocusPosition(userid, id);
		return Result.success();
	}
	
	/**
	 * 个人=》获取关注职位列表 (在个人中心)
	 * @Param userid 用户ID
	 * @Param usertype 用户类型
	 * @Param pagesize 每页数目
	 * @Param pagenow 当前页数
	 * */
	@RequestMapping("list")
	public String list(@Valid CurrencyDto currencyDto,BindingResult result) throws LMException{
		checkResult(result);
		
		return Result.success(focusPositionService.getFocusList(currencyDto));
	}

	
}
